package Aleehot100;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: c080
 * Package: Aleehot100
 * Description: 763. 划分字母区间
 *
 * @Author BCXJ
 * @Create 2025/9/4 05:50
 * @Version 1.0
 * @Since 1.0
 */
public class c080 {
    public static void main(String[] args) {
        System.out.println(partitionLabels("caedbdedda"));
    }

    public static List<Integer> partitionLabels(String s) {
        int[] endIndex = new int[26];
        char[] charArray = s.toCharArray();
        int index;
        for (int i = 0; i < charArray.length; i++) {
            index = charArray[i] - 'a';
            endIndex[index] = Math.max(endIndex[index], i);
        }

        int end = 0, start = 0;
        List<Integer> res = new ArrayList<>();
        // 切分
        for (int i = 0; i < charArray.length; i++) {
            index = charArray[i] - 'a';
            end = Math.max(end, endIndex[index]);
            if(i == end) {
                res.add(end - start + 1);
                start = end + 1;
            }
         }
        return res;
    }


}
